package com.lineage.server.model.skill;

import com.lineage.config.ConfigAlt;
import com.lineage.config.ConfigElfSkill;
import com.lineage.config.ConfigOther;
import com.lineage.config.ConfigWizardSkill;
import com.lineage.server.datatables.NpcTable;
import com.lineage.server.datatables.SkillsTable;
import com.lineage.server.datatables.lock.CharBookReading;
import com.lineage.server.model.Instance.L1EffectInstance;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1MonsterInstance;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.Instance.L1PetInstance;
import com.lineage.server.model.Instance.L1SummonInstance;
import com.lineage.server.model.L1CastleLocation;
import com.lineage.server.model.L1Character;
import com.lineage.server.model.L1Clan;
import com.lineage.server.model.L1Location;
import com.lineage.server.model.L1Magic;
import com.lineage.server.model.L1Object;
import com.lineage.server.model.L1PinkName;
import com.lineage.server.model.L1Teleport;
import com.lineage.server.model.L1War;
import com.lineage.server.model.poison.L1DamagePoison;
import com.lineage.server.model.skill.skillmode.SkillMode;
import com.lineage.server.serverpackets.S_ChangeHeading;
import com.lineage.server.serverpackets.S_Chat;
import com.lineage.server.serverpackets.S_CurseBlind;
import com.lineage.server.serverpackets.S_Dexup;
import com.lineage.server.serverpackets.S_DoActionGFX;
import com.lineage.server.serverpackets.S_Invis;
import com.lineage.server.serverpackets.S_NpcChat;
import com.lineage.server.serverpackets.S_OwnCharAttrDef;
import com.lineage.server.serverpackets.S_OwnCharStatus;
import com.lineage.server.serverpackets.S_PacketBox;
import com.lineage.server.serverpackets.S_PacketBoxIconAura;
import com.lineage.server.serverpackets.S_PacketBoxWindShackle;
import com.lineage.server.serverpackets.S_Paralysis;
import com.lineage.server.serverpackets.S_Poison;
import com.lineage.server.serverpackets.S_RangeSkill;
import com.lineage.server.serverpackets.S_RemoveObject;
import com.lineage.server.serverpackets.S_SPMR;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SkillBrave;
import com.lineage.server.serverpackets.S_SkillHaste;
import com.lineage.server.serverpackets.S_SkillIconShield;
import com.lineage.server.serverpackets.S_SkillSound;
import com.lineage.server.serverpackets.S_Sound;
import com.lineage.server.serverpackets.S_Strup;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.S_UseAttackSkill;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1Npc;
import com.lineage.server.templates.L1Skills;
import com.lineage.server.types.Point;
import com.lineage.server.utils.CheckUtil;
import com.lineage.server.utils.L1SpawnUtil;
import com.lineage.server.utils.RandomArrayList;
import com.lineage.server.world.World;
import com.lineage.server.world.WorldTrap;
import com.lineage.server.world.WorldWar;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class L1SkillUse {
  public static final int TYPE_NORMAL = 0;
  
  public static final int TYPE_LOGIN = 1;
  
  public static final int TYPE_SPELLSC = 2;
  
  public static final int TYPE_NPCBUFF = 3;
  
  public static final int TYPE_GMBUFF = 4;
  
  private static final Log _log = LogFactory.getLog(L1SkillUse.class);
  
  private static final int PC_PC = 1;
  
  private static final int PC_NPC = 2;
  
  private static final int NPC_PC = 3;
  
  private static final int NPC_NPC = 4;
  
  private static final int[] EXCEPT_COUNTER_MAGIC = new int[] { 
      1, 2, 3, 5, 8, 9, 12, 13, 14, 19, 
      21, 26, 31, 32, 35, 37, 42, 43, 48, 49, 
      52, 
      54, 55, 57, 60, 61, 63, 67, 68, 69, 
      72, 73, 75, 78, 79, 87, 88, 89, 90, 91, 
      97, 98, 99, 100, 101, 102, 
      104, 105, 106, 107, 
      109, 110, 111, 113, 114, 115, 116, 117, 118, 129, 
      130, 131, 132, 134, 137, 138, 146, 
      147, 148, 149, 
      150, 151, 155, 156, 158, 159, 161, 163, 164, 165, 
      166, 168, 169, 170, 171, 194, 213, 175, 
      176, 181, 
      185, 190, 195, 201, 204, 209, 211, 214, 216, 219, 
      208, 10026, 10027, 10028, 10029, 41472 };
  
  private static final int[][] REPEATEDSKILLS = new int[][] { { 148, 149, 155, 156, 163, 166 }, { 151, 168, 3, 99, 159 }, { 52, 101, 150, 1000, 1016, 1017, 186 }, { 43, 54, 1001 }, { 26, 110 }, { 42, 109 }, { 114, 115 }, { 201, 106 }, { 185, 190, 195 }, { 14 } };
  
  private L1Skills _skill;
  
  private int _skillId;
  
  private int _getBuffDuration;
  
  private int _shockStunDuration;
  
  private int _getBuffIconDuration;
  
  private int _targetID;
  
  private int _mpConsume;
  
  private int _hpConsume;
  
  private int _targetX;
  
  private int _targetY;
  
  private int _dmg;
  
  private int _skillTime;
  
  private int _type;
  
  private int _actid;
  
  private int _gfxid;
  
  private int _heal;
  
  private boolean _isPK;
  
  private int _bookmarkId;
  
  private int _bookmarkX = 0;
  
  private int _bookmarkY = 0;
  
  private int _itemobjid;
  
  private boolean _checkedUseSkill;
  
  private int _leverage;
  
  private boolean _isFreeze;
  
  private boolean _isCounterMagic;
  
  private boolean _isGlanceCheckFail;
  
  private L1Character _user;
  
  private L1PcInstance _player;
  
  private L1NpcInstance _npc;
  
  private L1Character _target;
  
  private L1NpcInstance _targetNpc;
  
  private int _calcType;
  
  private ArrayList<TargetStatus> _targetList;
  
  public L1SkillUse() {
    this._mpConsume = 0;
    this._hpConsume = 0;
    this._targetX = 0;
    this._targetY = 0;
    this._dmg = 0;
    this._skillTime = 0;
    this._type = 0;
    this._actid = 0;
    this._gfxid = 0;
    this._isPK = false;
    this._bookmarkId = 0;
    this._itemobjid = 0;
    this._checkedUseSkill = false;
    this._leverage = 10;
    this._isFreeze = false;
    this._isCounterMagic = true;
    this._isGlanceCheckFail = false;
    this._user = null;
    this._player = null;
    this._npc = null;
    this._target = null;
    this._targetNpc = null;
  }
  
  private static void summonMonster(L1PcInstance pc, String s) {
    int summonid = 0;
    int levelrange = 0;
    int summoncost = 0;
    String[] summonstr_list = { 
        "7", "263", "519", "8", "264", "520", "9", "265", "521", "10", 
        "266", "522", 
        "11", "267", "523", "12", "268", "524", "13", "269", 
        "525", "14", "270", "526", "15", "271", "527", 
        "16", "17", "18", 
        "274" };
    int[] summonid_list = { 
        81210, 81211, 81212, 81213, 81214, 81215, 81216, 81217, 81218, 81219, 
        81220, 
        81221, 81222, 81223, 81224, 81225, 81226, 81227, 81228, 81229, 
        81230, 81231, 81232, 81233, 81234, 81235, 
        81236, 81237, 81238, 81239, 
        81240 };
    int[] summonlvl_list = { 
        5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 
        5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 
        5, 5, 5, 5, 5, 5, 5, 
        5, 5, 5, 
        5 };
    int[] summoncha_list = { 
        8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 
        8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 
        8, 8, 8, 8, 8, 8, 8, 
        14, 36, 36, 
        44 };
    int loop = 0;
    while (loop < summonstr_list.length) {
      if (s.equalsIgnoreCase(summonstr_list[loop])) {
        summonid = summonid_list[loop];
        levelrange = summonlvl_list[loop];
        summoncost = summoncha_list[loop];
        break;
      } 
      loop++;
    } 
    if (pc.isWizard() && pc.getlogpcpower_SkillFor2() != 0 && pc.getlogpcpower_SkillFor2() >= 1 && 
      summonid == 81240)
      summonid = 93142 + pc.getlogpcpower_SkillFor2(); 
    if (pc.getLevel() < levelrange) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(743));
      return;
    } 
    if (pc.getCha() < summoncost) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(3039));
      return;
    } 
    int petcost = 0;
    Object[] petlist = pc.getPetList().values().toArray();
    Object[] array;
    int length = (array = petlist).length;
    int i = 0;
    while (i < length) {
      Object pet = array[i];
      petcost += ((L1NpcInstance)pet).getPetcost();
      i++;
    } 
    int pcCha = pc.getCha();
    int charisma = 0;
    int summoncount = 0;
    if (levelrange <= 56 || levelrange == 64) {
      if (pcCha > 34)
        pcCha = 34; 
    } else if (levelrange == 60) {
      if (pcCha > 30)
        pcCha = 30; 
    } else if (levelrange > 64 && pcCha > 44) {
      pcCha = 44;
    } 
    charisma = pc.getCha() + 6 - petcost;
    summoncount = charisma / summoncost;
    L1Npc npcTemp = NpcTable.get().getTemplate(summonid);
    int cnt = 0;
    while (cnt < summoncount) {
      L1SummonInstance summon = new L1SummonInstance(npcTemp, (L1Character)pc);
      summon.setPetcost(summoncost);
      cnt++;
    } 
  }
  
  public static void DoMySkillByMonster(L1PcInstance pc, int id) {
    if (pc.isDead())
      return; 
    if (pc.hasSkillEffect(id))
      return; 
    L1SkillUse l1skilluse = new L1SkillUse();
    l1skilluse.handleCommands(pc, id, pc.getId(), pc.getX(), pc.getY(), 0, 4);
  }
  
  public int getLeverage() {
    return this._leverage;
  }
  
  public void setLeverage(int i) {
    this._leverage = i;
  }
  
  private boolean isCheckedUseSkill() {
    return this._checkedUseSkill;
  }
  
  private void setCheckedUseSkill(boolean flg) {
    this._checkedUseSkill = flg;
  }
  
  public boolean checkUseSkill(L1PcInstance player, int skillid, int target_id, int x, int y, int time, int type, L1Character attacker) {
    return checkUseSkill(player, skillid, target_id, x, y, time, type, attacker, 0, 0);
  }
  
  public boolean checkUseSkill(L1PcInstance player, int skillid, int target_id, int x, int y, int time, int type, L1Character attacker, int actid, int gfxid) {
    setCheckedUseSkill(true);
    this._targetList = new ArrayList<>();
    this._skill = SkillsTable.get().getTemplate(skillid);
    if (this._skill == null)
      return false; 
    this._skillId = skillid;
    this._targetX = x;
    this._targetY = y;
    this._skillTime = time;
    this._type = type;
    this._actid = actid;
    this._gfxid = gfxid;
    boolean checkedResult = true;
    if (attacker == null) {
      this._player = player;
      this._user = (L1Character)this._player;
    } else {
      this._npc = (L1NpcInstance)attacker;
      this._user = (L1Character)this._npc;
    } 
    if (this._skill.getTarget().equals("none")) {
      this._targetID = this._user.getId();
      this._targetX = this._user.getX();
      this._targetY = this._user.getY();
    } else {
      this._targetID = target_id;
    } 
    switch (type) {
      case 0:
        checkedResult = isNormalSkillUsable();
        break;
      case 2:
      case 3:
        checkedResult = true;
        break;
    } 
    if (!checkedResult)
      return false; 
    if (this._skillId == 58 || this._skillId == 63)
      return true; 
    L1Object object = World.get().findObject(this._targetID);
    if (object instanceof L1ItemInstance)
      return false; 
    if (this._user instanceof L1PcInstance) {
      if (object instanceof L1PcInstance) {
        this._calcType = 1;
      } else {
        this._calcType = 2;
        this._targetNpc = (L1NpcInstance)object;
      } 
    } else if (this._user instanceof L1NpcInstance) {
      if (object instanceof L1PcInstance) {
        this._calcType = 3;
      } else {
        this._calcType = 4;
        this._targetNpc = (L1NpcInstance)object;
      } 
    } 
    switch (this._skillId) {
      case 5:
      case 69:
        this._bookmarkId = target_id;
        this._bookmarkX = x;
        this._bookmarkY = y;
        break;
      case 12:
      case 73:
      case 100:
      case 107:
        this._itemobjid = target_id;
        break;
      case 21:
        this._itemobjid = target_id;
        break;
    } 
    this._target = (L1Character)object;
    if (!(this._target instanceof L1MonsterInstance) && this._skill.getTarget().equals("attack") && 
      this._user.getId() != target_id)
      this._isPK = true; 
    if (!(object instanceof L1Character))
      checkedResult = false; 
    makeTargetList();
    if (this._user instanceof L1PcInstance) {
      L1PcInstance pc = (L1PcInstance)this._user;
      if (!ConfigAlt.NO_CD.equals("null")) {
        boolean nocd = false;
        String[] nocds = ConfigAlt.NO_CD.split(",");
        int i = 0;
        while (i < nocds.length) {
          if (Integer.valueOf(nocds[i]).intValue() == this._skillId) {
            nocd = true;
            break;
          } 
          i++;
        } 
        if (nocd && this._type != 4) {
          if (pc.hasSkillEffect(40000))
            return false; 
          if (!pc.hasSkillEffect(40000) && this._skill.getReuseDelay() > 0)
            pc.setSkillEffect(40000, this._skill.getReuseDelay()); 
        } 
      } 
    } 
    if (this._targetList.size() == 0 && this._user instanceof L1NpcInstance)
      checkedResult = false; 
    return checkedResult;
  }
  
  private boolean isNormalSkillUsable() {
    if (this._user instanceof L1PcInstance) {
      L1PcInstance pc = (L1PcInstance)this._user;
      if (!isAttrAgrees())
        return false; 
      if (this._skillId == 147 && pc.getElfAttr() == 0) {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage(280));
        return false;
      } 
      boolean castle_area = L1CastleLocation.checkInAllWarArea(this._player.getX(), this._player.getY(), 
          this._player.getMapId());
      int[] bow_GFX_Arrow = ConfigOther.WAR_DISABLE_SKILLS;
      int array[], length = (array = bow_GFX_Arrow).length;
      int i = 0;
      while (i < length) {
        int gfx = array[i];
        if (this._skillId == gfx && castle_area) {
          this._player.sendPackets((ServerBasePacket)new S_ServerMessage("11战争旗帜内禁止使用此魔法"));
          return false;
        } 
        i++;
      } 
      if (this._skillId == 205 || this._skillId == 210 || this._skillId == 215 || this._skillId == 220) {
        boolean isNearSameCube = false;
        int gfxId = 0;
        Iterator<L1Object> iterator = World.get().getVisibleObjects((L1Object)pc, 3).iterator();
        while (iterator.hasNext()) {
          L1Object obj = iterator.next();
          if (obj instanceof L1EffectInstance) {
            L1EffectInstance effect = (L1EffectInstance)obj;
            gfxId = effect.getGfxId();
            if ((this._skillId == 205 && gfxId == 6706) || (this._skillId == 210 && gfxId == 6712) || (
              this._skillId == 215 && gfxId == 6718) || (this._skillId == 220 && gfxId == 6724)) {
              isNearSameCube = true;
              break;
            } 
          } 
        } 
        if (isNearSameCube) {
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(1412));
          return false;
        } 
      } 
      if (!isItemConsume() && !this._player.isGm()) {
        this._player.sendPackets((ServerBasePacket)new S_ServerMessage(299));
        return false;
      } 
    } else if (this._user instanceof L1NpcInstance && this._user.hasSkillEffect(64)) {
      this._user.removeSkillEffect(64);
      return false;
    } 
    return isHPMPConsume();
  }
  
  public void handleCommands(L1PcInstance player, int skillId, int targetId, int x, int y, int timeSecs, int type) {
    handleCommands(player, skillId, targetId, x, y, timeSecs, type, null);
  }
  
  public void handleCommands(L1PcInstance player, int skillId, int targetId, int x, int y, int timeSecs, int type, L1Character attacker) {
    try {
      if (!isCheckedUseSkill()) {
        boolean isUseSkill = checkUseSkill(player, skillId, targetId, x, y, timeSecs, type, 
            attacker);
        if (!isUseSkill) {
          failSkill();
          return;
        } 
      } 
      switch (type) {
        case 0:
          if (!this._isGlanceCheckFail || this._skill.getArea() > 0 || this._skill.getTarget().equals("none")) {
            runSkill();
            useConsume();
            if (ConfigWizardSkill.DISINTEGRATE_CRITICAL_RND != 0 && skillId == 77) {
              L1Object target = World.get().findObject(targetId);
              if (target instanceof L1PcInstance) {
                L1PcInstance target_pc = (L1PcInstance)target;
                if (target_pc.isSafetyZone())
                  return; 
              } 
              if (player instanceof L1PcInstance) {
                L1PcInstance pc = player;
                Random random = new Random();
                if (random.nextInt(100) + 1 < ConfigWizardSkill.DISINTEGRATE_CRITICAL_RND) {
                  L1Object object = World.get().findObject(this._targetID);
                  this._target = (L1Character)object;
                  L1Magic magic = new L1Magic((L1Character)pc, this._target);
                  int codmg = magic.calcMagicDamage(77) * 2;
                  pc.sendPacketsAll((ServerBasePacket)new S_UseAttackSkill((L1Character)pc, targetId, ConfigWizardSkill.CRITICAL_SPR, x, 
                        y, 18, codmg));
                  magic.commit(codmg, 0);
                  return;
                } 
              } 
            } 
            sendGrfx(true);
            sendFailMessageHandle();
            setDelay();
          } 
          break;
        case 1:
          runSkill();
          break;
        case 2:
          runSkill();
          sendGrfx(true);
          setDelay();
          break;
        case 3:
          runSkill();
          sendGrfx(true);
          break;
        case 4:
          runSkill();
          sendGrfx(false);
          break;
        case 5:
          runSkill();
          sendGrfx(true);
          break;
      } 
      setCheckedUseSkill(false);
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  private void failSkill() {
    setCheckedUseSkill(false);
    switch (this._skillId) {
      case 5:
      case 69:
      case 131:
        this._player.sendPackets((ServerBasePacket)new S_Paralysis(7, false));
        break;
    } 
  }
  
  private boolean isTarget(L1Character cha) throws Exception {
    if (cha == null)
      return false; 
    if (this._npc != null) {
      if (this._npc.isHate(cha))
        return true; 
      if (this._npc instanceof L1PetInstance && cha instanceof L1MonsterInstance)
        return true; 
      if (this._npc instanceof L1SummonInstance && cha instanceof L1MonsterInstance)
        return true; 
    } 
    if (!CheckUtil.checkAttackSkill(cha))
      return false; 
    boolean flg = false;
    if (cha instanceof com.lineage.server.model.Instance.L1DoorInstance && (cha.getMaxHp() == 0 || cha.getMaxHp() == 1))
      return false; 
    if (cha instanceof com.lineage.server.model.Instance.L1DollInstance)
      return false; 
    if (cha instanceof com.lineage.server.model.Instance.L1HierarchInstance)
      return false; 
    if (cha instanceof L1PcInstance) {
      L1PcInstance pc = (L1PcInstance)cha;
      if (pc.isGhost() || pc.isGmInvis())
        return false; 
    } 
    if (this._calcType == 3) {
      if (cha instanceof L1PcInstance || cha instanceof L1PetInstance || cha instanceof com.lineage.server.model.Instance.L1DeInstance || 
        cha instanceof L1SummonInstance)
        flg = true; 
      if (cha instanceof com.lineage.server.model.Instance.L1DeInstance && cha.isSafetyZone())
        return false; 
    } 
    if (this._calcType == 2 && cha instanceof L1PcInstance && cha.isSafetyZone())
      return false; 
    if (this._calcType == 2 && this._target instanceof L1NpcInstance && !(this._target instanceof L1PetInstance) && 
      !(this._target instanceof L1SummonInstance) && (
      cha instanceof L1PetInstance || cha instanceof L1SummonInstance || cha instanceof L1PcInstance))
      return false; 
    if (this._calcType == 2 && this._target instanceof L1NpcInstance && !(this._target instanceof com.lineage.server.model.Instance.L1GuardInstance) && 
      cha instanceof com.lineage.server.model.Instance.L1GuardInstance)
      return false; 
    if ((this._skill.getTarget().equals("attack") || this._skill.getType() == 64) && this._calcType == 3 && 
      !(cha instanceof L1PetInstance) && !(cha instanceof L1SummonInstance) && 
      !(cha instanceof L1PcInstance))
      return false; 
    if ((this._skill.getTarget().equals("attack") || this._skill.getType() == 64) && this._calcType == 4 && 
      this._user instanceof L1MonsterInstance && cha instanceof L1MonsterInstance)
      return false; 
    if (this._skill.getTarget().equals("none") && this._skill.getType() == 64 && (
      cha instanceof com.lineage.server.model.Instance.L1CrownInstance || cha instanceof com.lineage.server.model.Instance.L1DwarfInstance || cha instanceof L1EffectInstance || 
      cha instanceof com.lineage.server.model.Instance.L1FieldObjectInstance || cha instanceof com.lineage.server.model.Instance.L1FurnitureInstance || 
      cha instanceof com.lineage.server.model.Instance.L1HousekeeperInstance || cha instanceof com.lineage.server.model.Instance.L1MerchantInstance || 
      cha instanceof com.lineage.server.model.Instance.L1TeleporterInstance))
      return false; 
    if (this._skill.getType() == 64 && cha.getId() == this._user.getId())
      return false; 
    if (cha.getId() == this._user.getId() && this._skillId == 49)
      return false; 
    if (((this._skill.getTargetTo() & 0x1) == 1 || (this._skill.getTargetTo() & 0x4) == 4 || (
      this._skill.getTargetTo() & 0x8) == 8) && cha.getId() == this._user.getId() && 
      this._skillId != 49)
      return true; 
    if (this._user instanceof L1PcInstance && (
      this._skill.getTarget().equals("attack") || this._skill.getType() == 64) && !this._isPK)
      if (cha instanceof L1SummonInstance) {
        L1SummonInstance summon = (L1SummonInstance)cha;
        if (this._player.getId() == summon.getMaster().getId())
          return false; 
      } else if (cha instanceof L1PetInstance) {
        L1PetInstance pet = (L1PetInstance)cha;
        if (this._player.getId() == pet.getMaster().getId())
          return false; 
      }  
    if ((this._skill.getTarget().equals("attack") || this._skill.getType() == 64) && 
      !(cha instanceof L1MonsterInstance) && !this._isPK && this._target instanceof L1PcInstance) {
      L1PcInstance enemy = null;
      try {
        enemy = (L1PcInstance)cha;
      } catch (Exception e) {
        return false;
      } 
      if (this._skillId == 72 && enemy.getZoneType() != 1 && (cha.hasSkillEffect(60) || cha.hasSkillEffect(97)))
        return true; 
      if (this._player.getClanid() != 0 && enemy.getClanid() != 0) {
        Iterator<L1War> iterator = WorldWar.get().getWarList().iterator();
        while (iterator.hasNext()) {
          L1War war = iterator.next();
          if (war.checkClanInWar(this._player.getClanname()) && 
            war.checkClanInSameWar(this._player.getClanname(), enemy.getClanname()) && 
            L1CastleLocation.checkInAllWarArea(enemy.getX(), enemy.getY(), enemy.getMapId()))
            return true; 
        } 
      } 
      return false;
    } 
    if (!this._user.glanceCheck(cha.getX(), cha.getY()) && !this._skill.isThrough() && this._skill.getType() != 2 && 
      this._skill.getType() != 32) {
      this._isGlanceCheckFail = true;
      return false;
    } 
    if (cha.hasSkillEffect(50) && this._skillId == 50)
      return false; 
    if (cha.hasSkillEffect(157) && this._skillId == 157)
      return false; 
    if (!(cha instanceof L1MonsterInstance) && (this._skillId == 36 || this._skillId == 41))
      return false; 
    if (cha.isDead() && this._skillId != 41 && this._skillId != 61 && this._skillId != 75 && this._skillId != 165)
      return false; 
    if (!cha.isDead() && (
      this._skillId == 41 || this._skillId == 61 || this._skillId == 75 || this._skillId == 165))
      return false; 
    if ((cha instanceof com.lineage.server.model.Instance.L1TowerInstance || cha instanceof com.lineage.server.model.Instance.L1DoorInstance) && (
      this._skillId == 41 || this._skillId == 61 || this._skillId == 75 || this._skillId == 165))
      return false; 
    if (cha instanceof L1PcInstance) {
      L1PcInstance pc = (L1PcInstance)cha;
      if (pc.hasSkillEffect(78)) {
        switch (this._skillId) {
          case 13:
          case 20:
          case 26:
          case 27:
          case 29:
          case 37:
          case 40:
          case 42:
          case 44:
          case 47:
          case 48:
          case 56:
          case 64:
          case 66:
          case 68:
          case 69:
          case 71:
          case 72:
          case 76:
          case 103:
          case 151:
          case 152:
          case 153:
          case 212:
            return true;
        } 
        return false;
      } 
    } 
    if (cha instanceof L1NpcInstance) {
      int hiddenStatus = ((L1NpcInstance)cha).getHiddenStatus();
      switch (hiddenStatus) {
        case 1:
          switch (this._skillId) {
            case 13:
            case 72:
            case 194:
            case 213:
              return true;
          } 
          return false;
        case 2:
          return false;
      } 
    } 
    if ((this._skill.getTargetTo() & 0x1) == 1 && cha instanceof L1PcInstance) {
      flg = true;
    } else if ((this._skill.getTargetTo() & 0x2) == 2 && (cha instanceof L1MonsterInstance || 
      cha instanceof L1NpcInstance || cha instanceof L1SummonInstance || cha instanceof L1PetInstance)) {
      flg = true;
    } else if ((this._skill.getTargetTo() & 0x10) == 16 && this._user instanceof L1PcInstance) {
      if (cha instanceof L1SummonInstance) {
        L1SummonInstance summon = (L1SummonInstance)cha;
        if (summon.getMaster() != null && this._player.getId() == summon.getMaster().getId())
          flg = true; 
      } 
      if (cha instanceof L1PetInstance) {
        L1PetInstance pet = (L1PetInstance)cha;
        if (pet.getMaster() != null && this._player.getId() == pet.getMaster().getId())
          flg = true; 
      } 
    } 
    if (this._calcType == 1 && cha instanceof L1PcInstance) {
      L1PcInstance xpc = (L1PcInstance)cha;
      if ((this._skill.getTargetTo() & 0x4) == 4 && ((
        this._player.getClanid() != 0 && this._player.getClanid() == xpc.getClanid()) || 
        this._player.isGm()))
        return true; 
      if ((this._skill.getTargetTo() & 0x8) == 8 && (
        this._player.getParty().isMember(xpc) || this._player.isGm()))
        return true; 
    } 
    return flg;
  }
  
  private boolean isParty(L1NpcInstance npc, L1Character cha) {
    if (npc.getMaster() == null)
      return false; 
    if (npc.isHate(cha))
      return false; 
    int masterId = npc.getMaster().getId();
    if (cha instanceof L1PcInstance)
      return (cha.getId() == masterId); 
    if (cha instanceof L1PetInstance) {
      L1PetInstance tgPet = (L1PetInstance)cha;
      return (tgPet.getMaster() != null && tgPet.getMaster().getId() == masterId);
    } 
    if (cha instanceof L1SummonInstance) {
      L1SummonInstance tgSu = (L1SummonInstance)cha;
      return (tgSu.getMaster() != null && tgSu.getMaster().getId() == masterId);
    } 
    return false;
  }
  
  private void makeTargetList() {
    try {
      ArrayList<L1Object> al1object;
      Iterator<L1Object> iterator;
      if (this._type == 1) {
        this._targetList.add(new TargetStatus(this._user));
        return;
      } 
      if (this._skill.getTargetTo() == 0 && (this._skill.getType() & 0x40) != 64) {
        this._targetList.add(new TargetStatus(this._user));
        return;
      } 
      if (this._skill.getRanged() != -1) {
        if (this._user.getLocation().getTileLineDistance((Point)this._target.getLocation()) > this._skill
          .getRanged())
          return; 
      } else if (!this._user.getLocation().isInScreen((Point)this._target.getLocation())) {
        return;
      } 
      if (!isTarget(this._target) && !this._skill.getTarget().equals("none"))
        return; 
      switch (this._skillId) {
        case 17:
          al1object = World.get().getVisibleLineObjects((L1Object)this._user, (L1Object)this._target);
          iterator = al1object.iterator();
          while (iterator.hasNext()) {
            L1Object tgobj = iterator.next();
            if (tgobj == null)
              continue; 
            if (!(tgobj instanceof L1Character))
              continue; 
            L1Character cha = (L1Character)tgobj;
            if (!isTarget(cha))
              continue; 
            this._targetList.add(new TargetStatus(cha));
          } 
          al1object.clear();
          return;
      } 
      if (this._skill.getArea() != 0) {
        List<L1Object> objects;
        if (!this._skill.getTarget().equals("none"))
          this._targetList.add(new TargetStatus(this._target)); 
        if (this._skillId != 49 && !this._skill.getTarget().equals("attack") && 
          this._skill.getType() != 64)
          this._targetList.add(new TargetStatus(this._user)); 
        if (this._skill.getArea() == -1) {
          objects = World.get().getVisibleObjects((L1Object)this._user);
        } else {
          objects = World.get().getVisibleObjects((L1Object)this._target, this._skill.getArea());
        } 
        Iterator<L1Object> iterator2 = objects.iterator();
        while (iterator2.hasNext()) {
          L1Object tgobj = iterator2.next();
          if (tgobj == null)
            continue; 
          if (!(tgobj instanceof L1Character))
            continue; 
          if (tgobj instanceof L1MonsterInstance) {
            L1MonsterInstance mob = (L1MonsterInstance)tgobj;
            if (mob.getNpcId() == 45166)
              continue; 
            if (mob.getNpcId() == 45167)
              continue; 
          } else if (tgobj instanceof L1PcInstance) {
            L1PcInstance tgpc = (L1PcInstance)tgobj;
            if ((this._skillId == 114 || this._skillId == 115 || this._skillId == 117) && 
              this._user instanceof L1PcInstance) {
              L1PcInstance pc = (L1PcInstance)this._user;
              if (pc.getClanid() != tgpc.getClanid())
                continue; 
              L1Clan clan = pc.getClan();
              L1PcInstance[] clanMembers = clan.getOnlineClanMember();
              L1PcInstance[] array;
              int length = (array = clanMembers).length;
              int i = 0;
              while (i < length) {
                L1PcInstance clanMember1 = array[i];
                if (pc.getLocation().isInScreen((Point)pc.getLocation())) {
                  int castgfx = this._skill.getCastGfx();
                  L1SkillUse skillUse = new L1SkillUse();
                  skillUse.handleCommands(clanMember1, castgfx, clanMember1.getId(), 
                      clanMember1.getX(), clanMember1.getY(), 1800, 4);
                } 
                i++;
              } 
            } 
          } 
          L1Character cha = (L1Character)tgobj;
          if (!isTarget(cha))
            continue; 
          this._targetList.add(new TargetStatus(cha));
        } 
        return;
      } 
      if (!this._user.glanceCheck(this._target.getX(), this._target.getY()) && (
        this._skill.getType() & 0x40) == 64 && this._skillId != 10026 && this._skillId != 10027 && 
        this._skillId != 10028 && this._skillId != 10029) {
        this._targetList.add(new TargetStatus(this._target, false));
        return;
      } 
      this._targetList.add(new TargetStatus(this._target));
    } catch (Exception exception) {}
  }
  
  private void sendHappenMessage(L1PcInstance pc) {
    int msgID = this._skill.getSysmsgIdHappen();
    if (msgID > 0)
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(msgID)); 
  }
  
  private void sendFailMessageHandle() {
    if (this._skill.getType() != 64 && !this._skill.getTarget().equals("none") && this._targetList.size() == 0)
      sendFailMessage(); 
  }
  
  private void sendFailMessage() {
    int msgID = this._skill.getSysmsgIdFail();
    if (msgID > 0 && this._user instanceof L1PcInstance)
      this._player.sendPackets((ServerBasePacket)new S_ServerMessage(msgID)); 
  }
  
  private boolean isAttrAgrees() {
    int magicattr = this._skill.getAttr();
    return !(!(this._user instanceof L1NpcInstance) && this._skill.getSkillLevel() >= 17 && 
      this._skill.getSkillLevel() <= 22 && magicattr != 0 && magicattr != this._player.getElfAttr() && 
      !this._player.isGm());
  }
  
  private boolean isHPMPConsume() {
    this._mpConsume = this._skill.getMpConsume();
    this._hpConsume = this._skill.getHpConsume();
    int currentMp = 0;
    int currentHp = 0;
    if (this._user instanceof L1NpcInstance) {
      currentMp = this._npc.getCurrentMp();
      currentHp = this._npc.getCurrentHp();
    } else {
      currentMp = this._player.getCurrentMp();
      currentHp = this._player.getCurrentHp();
      if (this._player.getOriginalMagicConsumeReduction() > 0)
        this._mpConsume -= this._player.getOriginalMagicConsumeReduction(); 
      if (this._player.getInt() > 12 && this._skillId > 8 && this._skillId <= 80)
        this._mpConsume--; 
      if (this._player.getInt() > 13 && this._skillId > 16 && this._skillId <= 80)
        this._mpConsume--; 
      if (this._player.getInt() > 14 && this._skillId > 23 && this._skillId <= 80)
        this._mpConsume--; 
      if (this._player.getInt() > 15 && this._skillId > 32 && this._skillId <= 80)
        this._mpConsume--; 
      if (this._player.getInt() > 16 && this._skillId > 40 && this._skillId <= 80)
        this._mpConsume--; 
      if (this._player.getInt() > 17 && this._skillId > 48 && this._skillId <= 80)
        this._mpConsume--; 
      if (this._player.getInt() > 18 && this._skillId > 56 && this._skillId <= 80)
        this._mpConsume--; 
      if (this._player.getInt() > 12 && this._skillId >= 87 && this._skillId <= 91)
        this._mpConsume -= this._player.getInt() - 12; 
      if (this._skillId == 26 && this._player.getInventory().checkEquipped(20013))
        this._mpConsume >>= 1; 
      if (this._skillId == 43 && this._player.getInventory().checkEquipped(20013))
        this._mpConsume >>= 1; 
      if (this._skillId == 1 && this._player.getInventory().checkEquipped(20014))
        this._mpConsume >>= 1; 
      if (this._skillId == 19 && this._player.getInventory().checkEquipped(20014))
        this._mpConsume >>= 1; 
      if (this._skillId == 12 && this._player.getInventory().checkEquipped(20015))
        this._mpConsume >>= 1; 
      if (this._skillId == 13 && this._player.getInventory().checkEquipped(20015))
        this._mpConsume >>= 1; 
      if (this._skillId == 42 && this._player.getInventory().checkEquipped(20015))
        this._mpConsume >>= 1; 
      if (this._skillId == 43 && this._player.getInventory().checkEquipped(20008))
        this._mpConsume >>= 1; 
      if (this._skillId == 54 && this._player.getInventory().checkEquipped(20023))
        this._mpConsume >>= 1; 
      if (this._skill.getMpConsume() == 0) {
        this._mpConsume = 0;
      } else if (this._mpConsume <= 0) {
        this._mpConsume = 1;
      } 
    } 
    if (currentHp < this._hpConsume + 1) {
      if (this._user instanceof L1PcInstance) {
        this._player.sendPackets((ServerBasePacket)new S_ServerMessage(279));
        if (this._player.isGm())
          this._player.setCurrentHp(this._player.getMaxHp()); 
      } 
      return false;
    } 
    if (this._skillId == 108 && currentHp <= 100) {
      if (this._user instanceof L1PcInstance)
        this._player.sendPackets((ServerBasePacket)new S_ServerMessage(279)); 
      return false;
    } 
    if (currentMp < this._mpConsume) {
      if (this._user instanceof L1PcInstance) {
        this._player.sendPackets((ServerBasePacket)new S_ServerMessage(278));
        if (this._player.isGm())
          this._player.setCurrentMp(this._player.getMaxMp()); 
      } 
      return false;
    } 
    return true;
  }
  
  private boolean isItemConsume() {
    int itemConsume = this._skill.getItemConsumeId();
    int itemConsumeCount = this._skill.getItemConsumeCount();
    return !(itemConsume != 0 && !this._player.isGm() && 
      !this._player.getInventory().checkItem(itemConsume, itemConsumeCount));
  }
  
  private void useConsume() {
    if (this._user instanceof L1NpcInstance) {
      int current_hp = this._npc.getCurrentHp() - this._hpConsume;
      this._npc.setCurrentHp(current_hp);
      int current_mp = this._npc.getCurrentMp() - this._mpConsume;
      this._npc.setCurrentMp(current_mp);
      return;
    } 
    if (isHPMPConsume())
      if (this._skillId == 108) {
        if (this._player.getlogpcpower_SkillFor4() != 0) {
          int hp = (int)(this._player.getCurrentHp() * 
            0.05D * this._player.getlogpcpower_SkillFor4());
          this._player.setCurrentHp(hp);
          this._player.setCurrentMp(1);
        } else {
          this._player.setCurrentHp(100);
          this._player.setCurrentMp(1);
        } 
      } else {
        int current_hp = this._player.getCurrentHp() - this._hpConsume;
        this._player.setCurrentHp(current_hp);
        int current_mp = this._player.getCurrentMp() - this._mpConsume;
        this._player.setCurrentMp(current_mp);
      }  
    int lawful = this._player.getLawful() + this._skill.getLawful();
    if (lawful > 32767)
      lawful = 32767; 
    if (lawful < -32767)
      lawful = -32767; 
    this._player.setLawful(lawful);
    int itemConsume = this._skill.getItemConsumeId();
    int itemConsumeCount = this._skill.getItemConsumeCount();
    if (itemConsume == 0 || this._player.isGm())
      return; 
    this._player.getInventory().consumeItem(itemConsume, itemConsumeCount);
  }
  
  private void addMagicList(L1Character cha, boolean repetition) {
    if (this._skillTime == 0) {
      this._getBuffDuration = this._skill.getBuffDuration() * 1000;
      if (this._skill.getBuffDuration() == 0) {
        if (this._skillId == 60)
          cha.setSkillEffect(60, 0); 
        return;
      } 
    } else {
      this._getBuffDuration = this._skillTime * 1000;
    } 
    if (this._skillId == 87 || this._skillId == 208)
      this._getBuffDuration = this._shockStunDuration; 
    if (this._skillId == 11)
      return; 
    if (this._skillId == 33 || this._skillId == 4001)
      return; 
    if (this._skillId == 67)
      return; 
    if (this._skillId == 21 || this._skillId == 8 || this._skillId == 12 || this._skillId == 48 || 
      this._skillId == 107)
      return; 
    if ((this._skillId == 50 || this._skillId == 80 || this._skillId == 194) && !this._isFreeze)
      return; 
    SkillMode mode = L1SkillMode.get().getSkill(this._skillId);
    if (mode == null)
      cha.setSkillEffect(this._skillId, this._getBuffDuration); 
    if (cha instanceof L1PcInstance && repetition) {
      L1PcInstance pc = (L1PcInstance)cha;
      sendIcon(pc);
    } 
  }
  
  private void sendIcon(L1PcInstance pc) {
    if (this._skillTime == 0) {
      this._getBuffIconDuration = this._skill.getBuffDuration();
    } else {
      this._getBuffIconDuration = this._skillTime;
    } 
    switch (this._skillId) {
      case 3:
        pc.sendPackets((ServerBasePacket)new S_SkillIconShield(5, this._getBuffIconDuration));
        break;
      case 99:
        pc.sendPackets((ServerBasePacket)new S_SkillIconShield(3, this._getBuffIconDuration));
        break;
      case 110:
        pc.sendPackets((ServerBasePacket)new S_Dexup(pc, 3, this._getBuffIconDuration));
        break;
      case 109:
        pc.sendPackets((ServerBasePacket)new S_Strup(pc, 3, this._getBuffIconDuration));
        break;
      case 114:
        pc.sendPackets((ServerBasePacket)new S_PacketBoxIconAura(113, this._getBuffIconDuration));
        break;
      case 115:
        pc.sendPackets((ServerBasePacket)new S_PacketBoxIconAura(114, this._getBuffIconDuration));
        break;
      case 117:
        pc.sendPackets((ServerBasePacket)new S_PacketBoxIconAura(116, this._getBuffIconDuration));
        break;
      case 148:
        pc.sendPackets((ServerBasePacket)new S_PacketBoxIconAura(147, this._getBuffIconDuration));
        break;
      case 149:
        pc.sendPackets((ServerBasePacket)new S_PacketBoxIconAura(148, this._getBuffIconDuration));
        break;
      case 155:
        pc.sendPackets((ServerBasePacket)new S_PacketBoxIconAura(154, this._getBuffIconDuration));
        break;
      case 156:
        pc.sendPackets((ServerBasePacket)new S_PacketBoxIconAura(155, this._getBuffIconDuration));
        break;
      case 159:
        pc.sendPackets((ServerBasePacket)new S_SkillIconShield(7, this._getBuffIconDuration));
        break;
      case 163:
        pc.sendPackets((ServerBasePacket)new S_PacketBoxIconAura(162, this._getBuffIconDuration));
        break;
      case 166:
        pc.sendPackets((ServerBasePacket)new S_PacketBoxIconAura(165, this._getBuffIconDuration));
        break;
      case 168:
        pc.sendPackets((ServerBasePacket)new S_SkillIconShield(10, this._getBuffIconDuration));
        break;
      case 151:
        pc.sendPackets((ServerBasePacket)new S_SkillIconShield(6, this._getBuffIconDuration));
        break;
      case 42:
        pc.sendPackets((ServerBasePacket)new S_Strup(pc, 5, this._getBuffIconDuration));
        break;
      case 26:
        pc.sendPackets((ServerBasePacket)new S_Dexup(pc, 5, this._getBuffIconDuration));
        break;
      case 43:
      case 54:
        pc.sendPackets((ServerBasePacket)new S_SkillHaste(pc.getId(), 1, this._getBuffIconDuration));
        pc.broadcastPacketAll((ServerBasePacket)new S_SkillHaste(pc.getId(), 1, 0));
        break;
      case 52:
      case 101:
      case 150:
        pc.sendPackets((ServerBasePacket)new S_SkillBrave(pc.getId(), 4, this._getBuffIconDuration));
        pc.broadcastPacketAll((ServerBasePacket)new S_SkillBrave(pc.getId(), 4, 0));
        break;
      case 29:
      case 76:
      case 152:
        pc.sendPackets((ServerBasePacket)new S_SkillHaste(pc.getId(), 2, this._getBuffIconDuration));
        pc.broadcastPacketAll((ServerBasePacket)new S_SkillHaste(pc.getId(), 2, 0));
        break;
      case 68:
        pc.sendPackets((ServerBasePacket)new S_PacketBox(40, this._getBuffIconDuration));
        break;
      case 167:
        pc.sendPackets((ServerBasePacket)new S_PacketBoxWindShackle(pc.getId(), this._getBuffIconDuration));
        break;
    } 
    pc.sendPackets((ServerBasePacket)new S_SPMR(pc));
    pc.sendPackets((ServerBasePacket)new S_OwnCharStatus(pc));
    pc.sendPackets((ServerBasePacket)new S_PacketBox(132, pc.getEr()));
  }
  
  private void sendGrfx(boolean isSkillAction) {
    if (this._actid == 0)
      this._actid = this._skill.getActionId(); 
    if (this._gfxid == 0) {
      this._gfxid = this._skill.getCastGfx();
      if (this._gfxid == 0)
        return; 
    } 
    if (this._user instanceof L1PcInstance) {
      if (this._player.isMagicCritical()) {
        int gfxid2 = this._skill.getCastGfx2();
        if (gfxid2 != 0)
          this._gfxid = gfxid2; 
      } 
      if (this._skillId == 58 || this._skillId == 63) {
        L1PcInstance pc = (L1PcInstance)this._user;
        if (this._skillId == 58) {
          pc.setHeading(pc.targetDirection(this._targetX, this._targetY));
          pc.sendPacketsAll((ServerBasePacket)new S_ChangeHeading((L1Character)pc));
        } 
        pc.sendPacketsAll((ServerBasePacket)new S_DoActionGFX(pc.getId(), this._actid));
        return;
      } 
      int targetid = this._target.getId();
      if (this._skillId == 87 || this._skillId == 208) {
        if (this._targetList.size() == 0)
          return; 
        if (this._target instanceof L1PcInstance) {
          L1PcInstance pc2 = (L1PcInstance)this._target;
          pc2.sendPacketsAll((ServerBasePacket)new S_SkillSound(pc2.getId(), 4434));
        } else if (this._target instanceof L1NpcInstance) {
          this._target.broadcastPacketAll((ServerBasePacket)new S_SkillSound(this._target.getId(), 4434));
        } 
        return;
      } 
      if (this._skillId == 2) {
        L1PcInstance pc2 = (L1PcInstance)this._target;
        pc2.sendPackets((ServerBasePacket)new S_Sound(145));
        if (pc2.isKnight() && pc2.getlogpcpower_SkillFor3() != 0 && pc2.getMeteLevel() > 0) {
          if (pc2.isEsoteric()) {
            pc2.setEsoteric(false);
            pc2.sendPackets((ServerBasePacket)new S_SystemMessage("\\fU关闭转身技能(圣法之盾)"));
          } else {
            pc2.setEsoteric(true);
            pc2.sendPackets((ServerBasePacket)new S_SystemMessage("\\fU开启转身技能(圣法之盾)"));
          } 
        } else if (pc2.isDarkelf() && pc2.getlogpcpower_SkillFor5() != 0 && pc2.getMeteLevel() > 0) {
          if (pc2.isEsoteric()) {
            pc2.setEsoteric(false);
            pc2.sendPackets((ServerBasePacket)new S_SystemMessage("\\fU关闭转生技能(刀剑之影)"));
          } else {
            pc2.setEsoteric(true);
            pc2.sendPackets((ServerBasePacket)new S_SystemMessage("\\fU开启转生技能(刀剑之影)"));
          } 
        } else if (pc2.isWizard() && pc2.getlogpcpower_SkillFor4() != 0 && pc2.getMeteLevel() > 0) {
          if (pc2.isEsoteric()) {
            pc2.setEsoteric(false);
            pc2.sendPackets((ServerBasePacket)new S_SystemMessage("\\fU关闭转生技能(粉碎爆发)"));
          } else {
            pc2.setEsoteric(true);
            int addMp = 0;
            if (pc2.getlogpcpower_SkillFor4() >= 1)
              addMp += pc2.getlogpcpower_SkillFor4() * 10; 
            pc2.sendPackets((ServerBasePacket)new S_SystemMessage("\\fU开启转生技能(粉碎爆发)，每秒消耗 " + addMp + " MP"));
          } 
        } else if (pc2.isCrown() && pc2.getlogpcpower_SkillFor2() != 0 && pc2.getMeteLevel() > 0) {
          if (pc2.isEsoteric()) {
            pc2.setEsoteric(false);
            pc2.sendPackets((ServerBasePacket)new S_SystemMessage("\\fU关闭转生技能(狂暴之气)"));
          } else {
            pc2.setEsoteric(true);
            pc2.sendPackets((ServerBasePacket)new S_SystemMessage("\\fU开启转生技能(狂暴之气)"));
          } 
        } 
      } 
      if (this._targetList.size() == 0 && !this._skill.getTarget().equals("none")) {
        int tempchargfx = this._player.getTempCharGfx();
        switch (tempchargfx) {
          case 5727:
          case 5730:
            this._actid = 19;
            break;
          case 5733:
          case 5736:
            this._actid = 1;
            break;
        } 
        if (isSkillAction)
          this._player.sendPacketsAll((ServerBasePacket)new S_DoActionGFX(this._player.getId(), this._actid)); 
        return;
      } 
      if (this._skill.getTarget().equals("attack") && this._skillId != 18) {
        if (isPcSummonPet(this._target) && (this._player.isSafetyZone() || this._target.isSafetyZone() || 
          this._player.checkNonPvP(this._player, this._target))) {
          this._player.sendPacketsAll((ServerBasePacket)new S_UseAttackSkill((L1Character)this._player, 0, this._gfxid, this._targetX, 
                this._targetY, this._actid, this._dmg));
          return;
        } 
        if (this._skill.getArea() == 0) {
          this._player.sendPacketsAll((ServerBasePacket)new S_UseAttackSkill((L1Character)this._player, targetid, this._gfxid, this._targetX, 
                this._targetY, this._actid, this._dmg));
        } else {
          this._player.sendPacketsAll(
              (ServerBasePacket)new S_RangeSkill((L1Character)this._player, this._targetList, this._gfxid, this._actid, 8));
        } 
      } else if (this._skill.getTarget().equals("none") && this._skill.getType() == 64) {
        this._player
          .sendPacketsAll((ServerBasePacket)new S_RangeSkill((L1Character)this._player, this._targetList, this._gfxid, this._actid, 0));
      } else {
        if (this._skillId != 5 && this._skillId != 69 && this._skillId != 131) {
          if (isSkillAction)
            this._player.sendPacketsAll((ServerBasePacket)new S_DoActionGFX(this._player.getId(), this._actid)); 
          if (this._skillId == 31 || this._skillId == 91 || this._skillId == 112 || this._skillId == 134) {
            this._player.sendPackets((ServerBasePacket)new S_SkillSound(targetid, this._gfxid));
            this._player.broadcastPacketAll((ServerBasePacket)new S_SkillSound(targetid, this._gfxid));
          } else {
            if (this._skillId == 113)
              return; 
            if (this._skillId == 1 || this._skillId == 19 || this._skillId == 35 || this._skillId == 57) {
              this._player.sendPacketsAllUnderInvis((ServerBasePacket)new S_SkillSound(targetid, this._gfxid));
            } else if (this._skillId == 68) {
              this._player.sendPacketsAllUnderInvis((ServerBasePacket)new S_SkillSound(targetid, this._gfxid));
              if (this._calcType == 1 && this._player.getId() != this._target.getId() && 
                this._target.hasSkillEffect(5122))
                L1PinkName.runPinkNameTimer(this._player); 
            } else if (this._skillId == 185 || this._skillId == 190 || this._skillId == 195) {
              if (this._skillId != this._player.getAwakeSkillId())
                return; 
              this._player.sendPacketsAll((ServerBasePacket)new S_SkillSound(targetid, this._gfxid));
            } else if (this._skillId == 106 && this._player.getAc() <= -100) {
              this._gfxid = this._skill.getCastGfx2();
              this._player.sendPacketsAll((ServerBasePacket)new S_SkillSound(targetid, this._gfxid));
            } else {
              this._player.sendPacketsAll((ServerBasePacket)new S_SkillSound(targetid, this._gfxid));
            } 
          } 
        } 
        Iterator<TargetStatus> iterator = this._targetList.iterator();
        while (iterator.hasNext()) {
          TargetStatus ts = iterator.next();
          L1Character cha = ts.getTarget();
          if (cha instanceof L1PcInstance) {
            L1PcInstance pc3 = (L1PcInstance)cha;
            pc3.sendPackets((ServerBasePacket)new S_OwnCharStatus(pc3));
          } 
        } 
      } 
      this._player.setMagicCritical(false);
    } else if (this._user instanceof L1NpcInstance) {
      int targetid = this._target.getId();
      if (this._user instanceof com.lineage.server.model.Instance.L1MerchantInstance) {
        this._user.broadcastPacketAll((ServerBasePacket)new S_SkillSound(targetid, this._gfxid));
        return;
      } 
      if (this._targetList.size() == 0 && !this._skill.getTarget().equals("none")) {
        this._user.broadcastPacketAll((ServerBasePacket)new S_DoActionGFX(this._user.getId(), this._actid));
        return;
      } 
      if (this._skill.getTarget().equals("attack") && this._skillId != 18) {
        if (this._skill.getArea() == 0) {
          this._user.broadcastPacketAll((ServerBasePacket)new S_UseAttackSkill(this._user, targetid, this._gfxid, this._targetX, 
                this._targetY, this._actid, this._dmg));
        } else {
          this._user.broadcastPacketAll(
              (ServerBasePacket)new S_RangeSkill(this._user, this._targetList, this._gfxid, this._actid, 8));
        } 
      } else if (this._skill.getTarget().equals("none") && this._skill.getType() == 64) {
        this._user.broadcastPacketAll(
            (ServerBasePacket)new S_RangeSkill(this._user, this._targetList, this._gfxid, this._actid, 0));
      } else if (this._skillId != 5 && this._skillId != 69 && this._skillId != 131) {
        this._user.broadcastPacketAll((ServerBasePacket)new S_DoActionGFX(this._user.getId(), this._actid));
        this._user.broadcastPacketAll((ServerBasePacket)new S_SkillSound(targetid, this._gfxid));
      } 
    } 
  }
  
  private void deleteRepeatedSkills(L1Character cha) {
    int repeatedskills[][], length = (repeatedskills = REPEATEDSKILLS).length;
    int i = 0;
    while (i < length) {
      int[] skills = repeatedskills[i];
      int array[], length2 = (array = skills).length;
      int j = 0;
      while (j < length2) {
        int id = array[j];
        if (id == this._skillId)
          stopSkillList(cha, skills); 
        j++;
      } 
      i++;
    } 
  }
  
  private void stopSkillList(L1Character cha, int[] repeat_skill) {
    int length = repeat_skill.length;
    int i = 0;
    while (i < length) {
      int skillId = repeat_skill[i];
      if (skillId != this._skillId)
        cha.removeSkillEffect(skillId); 
      i++;
    } 
  }
  
  private void setDelay() {
    if (this._skill.getReuseDelay() > 0)
      L1SkillDelay.onSkillUse(this._user, this._skill.getReuseDelay()); 
  }
  
  private void runSkill() {
    switch (this._skillId) {
      case 63:
        L1SpawnUtil.spawnEffect(81169, this._skill.getBuffDuration(), this._targetX, this._targetY, 
            this._user.getMapId(), this._user, 0);
        return;
      case 205:
        L1SpawnUtil.spawnEffect(80149, this._skill.getBuffDuration(), this._targetX, this._targetY, 
            this._user.getMapId(), this._user, this._skillId);
        return;
      case 210:
        L1SpawnUtil.spawnEffect(80150, this._skill.getBuffDuration(), this._targetX, this._targetY, 
            this._user.getMapId(), this._user, this._skillId);
        return;
      case 215:
        L1SpawnUtil.spawnEffect(80151, this._skill.getBuffDuration(), this._targetX, this._targetY, 
            this._user.getMapId(), this._user, this._skillId);
        return;
      case 220:
        L1SpawnUtil.spawnEffect(80152, this._skill.getBuffDuration(), this._targetX, this._targetY, 
            this._user.getMapId(), this._user, this._skillId);
        return;
      case 58:
        L1SpawnUtil.doSpawnFireWall(this._user, this._targetX, this._targetY);
        return;
    } 
    int except_COUNTER_MAGIC[], length = (except_COUNTER_MAGIC = EXCEPT_COUNTER_MAGIC).length;
    int i = 0;
    while (i < length) {
      int skillId = except_COUNTER_MAGIC[i];
      if (this._skillId == skillId) {
        this._isCounterMagic = false;
        break;
      } 
      i++;
    } 
    if (this._skillId == 87 && this._user instanceof L1PcInstance)
      this._target.onAction(this._player); 
    if (this._skillId == 208 && this._user instanceof L1PcInstance)
      this._target.onAction(this._player); 
    if (!isTargetCalc(this._target))
      return; 
    try {
      TargetStatus ts = null;
      L1Character cha = null;
      int drainMana = 0;
      boolean isSuccess = false;
      int undeadType = 0;
      int heal = 0;
      Iterator<TargetStatus> iter = this._targetList.iterator();
      while (iter.hasNext()) {
        double con1;
        int Int;
        ts = null;
        cha = null;
        isSuccess = false;
        undeadType = 0;
        ts = iter.next();
        cha = ts.getTarget();
        if (this._npc != null) {
          if (this._npc instanceof L1PetInstance && isParty(this._npc, cha)) {
            ts.isCalc(false);
            this._dmg = 0;
            continue;
          } 
          if (this._npc instanceof L1SummonInstance && isParty(this._npc, cha)) {
            ts.isCalc(false);
            this._dmg = 0;
            continue;
          } 
        } 
        if (!ts.isCalc() || !isTargetCalc(cha)) {
          ts.isCalc(false);
          continue;
        } 
        L1Magic magic = new L1Magic(this._user, cha);
        magic.setLeverage(getLeverage());
        if (cha instanceof L1MonsterInstance)
          undeadType = ((L1MonsterInstance)cha).getNpcTemplate().get_undead(); 
        if ((this._skill.getType() == 4 || this._skill.getType() == 1) && isTargetFailure(cha)) {
          iter.remove();
          continue;
        } 
        if (cha instanceof L1PcInstance || cha instanceof L1NpcInstance)
          if (this._skillTime == 0) {
            this._getBuffIconDuration = this._skill.getBuffDuration();
          } else {
            this._getBuffIconDuration = this._skillTime;
          }  
        deleteRepeatedSkills(cha);
        switch (this._skill.getType()) {
          case 64:
            if (this._user.getId() == cha.getId())
              break; 
            if (isUseCounterMagic(cha)) {
              iter.remove();
              continue;
            } 
            this._dmg = magic.calcMagicDamage(this._skillId);
            if (cha.hasSkillEffect(153))
              cha.removeSkillEffect(153); 
            break;
          case 1:
          case 4:
            isSuccess = magic.calcProbabilityMagic(this._skillId);
            if (this._type == 4)
              isSuccess = true; 
            if (cha.hasSkillEffect(153) && this._skillId != 153)
              cha.removeSkillEffect(153); 
            if (this._skillId != 66 || this._skillId != 212 || this._skillId != 103) {
              cha.removeSkillEffect(66);
              cha.removeSkillEffect(212);
              cha.removeSkillEffect(103);
            } 
            if (!isSuccess) {
              if ((this._skillId == 66 || this._skillId == 212 || this._skillId == 103) && 
                cha instanceof L1PcInstance) {
                L1PcInstance pc = (L1PcInstance)cha;
                pc.sendPackets((ServerBasePacket)new S_ServerMessage(297));
              } 
              iter.remove();
              continue;
            } 
            if (isUseCounterMagic(cha)) {
              iter.remove();
              continue;
            } 
            if (this._skillId == 174 && cha instanceof L1PcInstance) {
              L1PcInstance pc = (L1PcInstance)cha;
              pc.sendPackets((ServerBasePacket)new S_PacketBox(132, 0));
            } 
            break;
          case 16:
            if (this._player == null)
              break; 
            this._heal = magic.calcHealing(this._skillId);
            if (cha.hasSkillEffect(170))
              this._heal <<= 1; 
            if (cha.hasSkillEffect(173))
              this._heal >>= 1; 
            if (cha.hasSkillEffect(4012))
              this._heal >>= 1; 
            if (cha.hasSkillEffect(4013))
              this._heal *= -1; 
            if (this._skillId == 164 && this._player.getlogpcpower_SkillFor3() != 0 && 
              this._player.getlogpcpower_SkillFor3() >= 1 && 
              RandomArrayList.getInc(100, 1) <= this._player.getlogpcpower_SkillFor3()) {
              this._heal *= 2;
              this._player.sendPackets((ServerBasePacket)new S_SkillSound(this._player.getId(), 5377));
            } 
            if (cha.isPinkName())
              L1PinkName.runPinkNameTimer(this._player); 
            con1 = 1.0D;
            Int = 1;
            if (this._player.getInt() > 0)
              while (Int < this._player.getInt() / 15) {
                con1 += 0.1D;
                Int++;
              }  
            this._heal = (int)(this._heal * con1);
            if (this._player.isGm())
              this._player.sendPackets((ServerBasePacket)new S_SystemMessage("治愈:" + this._heal)); 
            break;
        } 
        SkillMode mode = L1SkillMode.get().getSkill(this._skillId);
        if (mode != null) {
          if (this._user instanceof L1PcInstance)
            switch (this._skillId) {
              case 5:
              case 69:
                if (this._bookmarkX > 0 && this._bookmarkY > 0) {
                  int book_id = CharBookReading.get().getBookId(this._player, this._bookmarkX, this._bookmarkY, this._bookmarkId);
                  this._dmg = mode.start(this._player, cha, magic, book_id);
                  break;
                } 
                this._dmg = mode.start(this._player, cha, magic, 0);
                break;
              case 116:
              case 118:
                this._dmg = mode.start(this._player, cha, magic, this._targetID);
                break;
              default:
                this._dmg = mode.start(this._player, cha, magic, this._getBuffIconDuration);
                break;
            }  
          if (this._user instanceof L1NpcInstance)
            this._dmg = mode.start(this._npc, cha, magic, this._getBuffIconDuration); 
        } else if (cha.hasSkillEffect(this._skillId)) {
          addMagicList(cha, true);
          continue;
        } 
        if (this._skillId == 13 || this._skillId == 194 || this._skillId == 213) {
          if (cha instanceof L1NpcInstance) {
            L1NpcInstance npc = (L1NpcInstance)cha;
            int hiddenStatus = npc.getHiddenStatus();
            if (hiddenStatus == 1)
              npc.appearOnGround(this._player); 
          } 
        } else if (this._skillId == 72) {
          if (cha instanceof L1PcInstance) {
            this._dmg = magic.calcMagicDamage(this._skillId);
          } else if (cha instanceof L1NpcInstance) {
            L1NpcInstance npc = (L1NpcInstance)cha;
            int hiddenStatus = npc.getHiddenStatus();
            if (hiddenStatus == 1) {
              npc.appearOnGround(this._player);
            } else {
              this._dmg = 0;
            } 
          } else {
            this._dmg = 0;
          } 
        } else if (this._skillId == 1 || this._skillId == 19 || this._skillId == 35 || 
          this._skillId == 57 || this._skillId == 49 || this._skillId == 158 || 
          this._skillId == 164) {
          if (this._user instanceof L1PcInstance)
            cha.removeSkillEffect(170); 
        } else if (this._skillId == 10 || this._skillId == 28) {
          heal = this._dmg;
        } else if (this._skillId == 10026 || this._skillId == 10027 || this._skillId == 10028 || 
          this._skillId == 10029) {
          if (this._user instanceof L1NpcInstance) {
            this._user.broadcastPacketAll(
                (ServerBasePacket)new S_NpcChat(this._npc, (L1PcInstance)this._target, "$3717"));
          } else {
            this._player.broadcastPacketAll((ServerBasePacket)new S_Chat(this._player, "$3717"));
          } 
        } else if (this._skillId == 10057) {
          L1Teleport.teleportToTargetFront(cha, this._user, 1);
        } else if (this._skillId == 10058) {
          if (this._calcType == 3) {
            List<L1Object> objects = World.get().getVisibleObjects((L1Object)this._user, 12);
            Iterator<L1Object> iterator = objects.iterator();
            while (iterator.hasNext()) {
              L1Object tgobj = iterator.next();
              if (tgobj == null)
                continue; 
              if (tgobj == this._user)
                continue; 
              if (!(tgobj instanceof L1PcInstance))
                continue; 
              L1PcInstance cha2 = (L1PcInstance)tgobj;
              L1Teleport.teleportToTargetFront((L1Character)cha2, this._user, 1);
            } 
          } 
        } else if (this._skillId == 29 || this._skillId == 76 || this._skillId == 152) {
          int skillNum;
          if (cha instanceof L1PcInstance) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            if (pc2.getHasteItemEquipped() > 0)
              continue; 
          } 
          if (cha.getBraveSpeed() == 5)
            continue; 
          switch (cha.getMoveSpeed()) {
            case 0:
              if (cha instanceof L1PcInstance) {
                L1PcInstance pc2 = (L1PcInstance)cha;
                pc2.sendPackets((ServerBasePacket)new S_SkillHaste(pc2.getId(), 2, this._getBuffIconDuration));
              } 
              cha.broadcastPacketAll((ServerBasePacket)new S_SkillHaste(cha.getId(), 2, this._getBuffIconDuration));
              cha.setMoveSpeed(2);
              break;
            case 1:
              skillNum = 0;
              if (cha.hasSkillEffect(43)) {
                skillNum = 43;
              } else if (cha.hasSkillEffect(54)) {
                skillNum = 54;
              } else if (cha.hasSkillEffect(1001)) {
                skillNum = 1001;
              } 
              if (skillNum != 0) {
                cha.removeSkillEffect(skillNum);
                cha.removeSkillEffect(this._skillId);
                cha.setMoveSpeed(0);
                continue;
              } 
              break;
          } 
        } else if (this._skillId == 77) {
          if (this._user instanceof L1PcInstance) {
            L1PcInstance srcpc = (L1PcInstance)this._user;
            Random random = new Random();
            if (ConfigWizardSkill.DISINTEGRATE_RND != 0 && 
              random.nextInt(100) + 1 < ConfigWizardSkill.DISINTEGRATE_RND) {
              int codmg = magic.calcMagicDamage(77);
              srcpc.sendPacketsAll((ServerBasePacket)new S_UseAttackSkill((L1Character)srcpc, cha.getId(), 
                    ConfigWizardSkill.SPR, cha.getX(), cha.getY(), 18, codmg));
              magic.commit(codmg, drainMana);
            } 
          } 
        } else if (this._skillId == 11) {
          L1DamagePoison.doInfection(this._user, cha, 3000, 5);
        } else if (this._skillId == 47) {
          if (cha instanceof L1PcInstance) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addDmgup(-5);
            pc2.addHitup(-1);
          } 
        } else if (this._skillId == 56) {
          if (cha instanceof L1PcInstance) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addHitup(-6);
            pc2.addAc(12);
          } 
        } else if (this._skillId == 157) {
          if (cha instanceof L1PcInstance) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            boolean castle_area = L1CastleLocation.checkInAllWarArea(pc2.getX(), 
                pc2.getY(), pc2.getMapId());
            if (castle_area)
              return; 
            pc2.sendPacketsAll((ServerBasePacket)new S_Poison(pc2.getId(), 2));
            pc2.sendPackets((ServerBasePacket)new S_Paralysis(4, true));
            if (pc2.hasSkillEffect(1010) || pc2.hasSkillEffect(1011))
              pc2.cureParalaysis(); 
          } else if (cha instanceof L1MonsterInstance || cha instanceof L1SummonInstance || 
            cha instanceof L1PetInstance) {
            L1NpcInstance npc = (L1NpcInstance)cha;
            npc.broadcastPacketAll((ServerBasePacket)new S_Poison(npc.getId(), 2));
            npc.setParalyzed(true);
          } 
        } else if (this._skillId == 50) {
          this._isFreeze = magic.calcProbabilityMagic(this._skillId);
          if (this._isFreeze) {
            int time = this._skill.getBuffDuration() + 1;
            if (cha instanceof L1PcInstance) {
              L1PcInstance pc3 = (L1PcInstance)cha;
              boolean castle_area2 = L1CastleLocation.checkInAllWarArea(pc3.getX(), 
                  pc3.getY(), pc3.getMapId());
              if (castle_area2 && pc3.castleWarResult())
                return; 
              L1SpawnUtil.spawnEffect(81168, time, pc3.getX(), pc3.getY(), 
                  this._user.getMapId(), this._user, 0);
              pc3.sendPacketsAll((ServerBasePacket)new S_Poison(pc3.getId(), 2));
              pc3.sendPackets((ServerBasePacket)new S_Paralysis(4, true));
            } else if (cha instanceof L1MonsterInstance || cha instanceof L1SummonInstance || 
              cha instanceof L1PetInstance) {
              L1NpcInstance npc2 = (L1NpcInstance)cha;
              L1SpawnUtil.spawnEffect(81168, time, npc2.getX(), npc2.getY(), 
                  this._user.getMapId(), this._user, 0);
              npc2.broadcastPacketAll((ServerBasePacket)new S_Poison(npc2.getId(), 2));
              npc2.setParalyzed(true);
            } 
          } 
        } else if (this._skillId == 80) {
          this._isFreeze = magic.calcProbabilityMagic(this._skillId);
          if (this._isFreeze) {
            int time = this._skill.getBuffDuration() + 1;
            if (cha instanceof L1PcInstance) {
              L1PcInstance l1PcInstance = (L1PcInstance)cha;
            } else if (cha instanceof L1MonsterInstance || cha instanceof L1SummonInstance || 
              cha instanceof L1PetInstance) {
              L1NpcInstance npc2 = (L1NpcInstance)cha;
              L1SpawnUtil.spawnEffect(81168, time, npc2.getX(), npc2.getY(), 
                  this._user.getMapId(), this._user, 0);
              npc2.broadcastPacketAll((ServerBasePacket)new S_Poison(npc2.getId(), 2));
              npc2.setParalyzed(true);
            } 
          } 
        } else if (this._skillId == 40) {
          if (cha instanceof L1PcInstance) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            if (pc2.hasSkillEffect(1012)) {
              pc2.sendPackets((ServerBasePacket)new S_CurseBlind(2));
            } else {
              pc2.sendPackets((ServerBasePacket)new S_CurseBlind(1));
            } 
          } 
        } else if (this._skillId == 18) {
          if (undeadType == 1 || undeadType == 3)
            this._dmg = cha.getCurrentHp(); 
        } else if (this._skillId == 39) {
          Random random2 = new Random();
          int chance = random2.nextInt(10) + 5;
          drainMana = chance + this._user.getInt() / 2;
          if (cha.getCurrentMp() < drainMana)
            drainMana = cha.getCurrentMp(); 
        } else if (this._skillId == 27) {
          if (this._calcType == 1 || this._calcType == 3) {
            if (cha instanceof L1PcInstance) {
              L1PcInstance pc2 = (L1PcInstance)cha;
              L1ItemInstance weapon = pc2.getWeapon();
              if (weapon != null) {
                Random random3 = new Random();
                int weaponDamage = random3.nextInt(this._user.getInt() / 3) + 1;
                pc2.sendPackets((ServerBasePacket)new S_ServerMessage(268, weapon.getLogName()));
                pc2.getInventory().receiveDamage(weapon, weaponDamage);
              } 
            } 
          } else {
            ((L1NpcInstance)cha).setWeaponBreaked(true);
          } 
        } else if (this._skillId == 66) {
          if (cha instanceof L1PcInstance) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.sendPackets((ServerBasePacket)new S_Paralysis(3, true));
          } 
          cha.setSleeped(true);
        } else if (this._skillId == 183) {
          if (cha instanceof L1PcInstance) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addAc(10);
          } 
        } else if (this._skillId == 193 && cha instanceof L1PcInstance) {
          L1PcInstance pc2 = (L1PcInstance)cha;
          pc2.addStr(-3);
          pc2.addInt(-3);
        } 
        if (this._calcType == 1 || this._calcType == 3) {
          if (this._skillId == 73) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            L1ItemInstance item = pc2.getInventory().getItem(this._itemobjid);
            if (item != null && item.getItem().getType2() == 1) {
              int item_type = item.getItem().getType2();
              int safe_enchant = item.getItem().get_safeenchant();
              int enchant_level = item.getEnchantLevel();
              String item_name = item.getName();
              if (safe_enchant < 0) {
                pc2.sendPackets((ServerBasePacket)new S_ServerMessage(79));
              } else if (safe_enchant == 0) {
                pc2.sendPackets((ServerBasePacket)new S_ServerMessage(79));
              } else if (item_type == 1 && enchant_level == 0) {
                if (!item.isIdentified()) {
                  pc2.sendPackets((ServerBasePacket)new S_ServerMessage(161, item_name, "$245", "$247"));
                } else {
                  item_name = "+0 " + item_name;
                  pc2.sendPackets(
                      (ServerBasePacket)new S_ServerMessage(161, "+0 " + item_name, "$245", "$247"));
                } 
                item.setEnchantLevel(1);
                pc2.getInventory().updateItem(item, 4);
              } else {
                pc2.sendPackets((ServerBasePacket)new S_ServerMessage(79));
              } 
            } else {
              pc2.sendPackets((ServerBasePacket)new S_ServerMessage(79));
            } 
          } else if (this._skillId == 100) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            Random random = new Random();
            L1ItemInstance item2 = pc2.getInventory().getItem(this._itemobjid);
            if (item2 != null) {
              int dark = (int)(10.0D + pc2.getLevel() * 0.8D + (pc2.getWis() - 6) * 1.2D);
              int brave = (int)(dark / 2.1D);
              int wise = (int)(brave / 2.0D);
              int kayser = (int)(wise / 1.9D);
              int chance2 = random.nextInt(100) + 1;
              if (item2.getItem().getItemId() == 40320) {
                pc2.getInventory().removeItem(item2, 1L);
                if (dark >= chance2) {
                  pc2.getInventory().storeItem(40321, 1L);
                  pc2.sendPackets((ServerBasePacket)new S_ServerMessage(403, "$2475"));
                } else {
                  pc2.sendPackets((ServerBasePacket)new S_ServerMessage(280));
                } 
              } else if (item2.getItem().getItemId() == 40321) {
                pc2.getInventory().removeItem(item2, 1L);
                if (brave >= chance2) {
                  pc2.getInventory().storeItem(40322, 1L);
                  pc2.sendPackets((ServerBasePacket)new S_ServerMessage(403, "$2476"));
                } else {
                  pc2.sendPackets((ServerBasePacket)new S_ServerMessage(280));
                } 
              } else if (item2.getItem().getItemId() == 40322) {
                pc2.getInventory().removeItem(item2, 1L);
                if (wise >= chance2) {
                  pc2.getInventory().storeItem(40323, 1L);
                  pc2.sendPackets((ServerBasePacket)new S_ServerMessage(403, "$2477"));
                } else {
                  pc2.sendPackets((ServerBasePacket)new S_ServerMessage(280));
                } 
              } else if (item2.getItem().getItemId() == 40323) {
                pc2.getInventory().removeItem(item2, 1L);
                if (kayser >= chance2) {
                  pc2.getInventory().storeItem(40324, 1L);
                  pc2.sendPackets((ServerBasePacket)new S_ServerMessage(403, "$2478"));
                } else {
                  pc2.sendPackets((ServerBasePacket)new S_ServerMessage(280));
                } 
              } 
            } 
          } else if (this._skillId == 78) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.stopHpRegeneration();
            pc2.stopMpRegeneration();
          } 
          if (this._skillId == 2) {
            if (this._skillId == 2) {
              L1PcInstance pc2 = (L1PcInstance)this._target;
              pc2.sendPackets((ServerBasePacket)new S_Sound(145));
            } 
          } else if (this._skillId == 114) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addHitup(5);
            pc2.addBowHitup(5);
            pc2.addMr(20);
            pc2.sendPackets((ServerBasePacket)new S_SPMR(pc2));
            pc2.sendPackets((ServerBasePacket)new S_PacketBoxIconAura(113, this._getBuffIconDuration));
          } else if (this._skillId == 115) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addAc(-8);
            pc2.sendPackets((ServerBasePacket)new S_PacketBoxIconAura(114, this._getBuffIconDuration));
          } else if (this._skillId == 117) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addDmgup(5);
            pc2.sendPackets((ServerBasePacket)new S_PacketBoxIconAura(116, this._getBuffIconDuration));
          } else if (this._skillId == 3) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addAc(-2);
            pc2.sendPackets((ServerBasePacket)new S_SkillIconShield(5, this._getBuffIconDuration));
          } else if (this._skillId == 110) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addDex(3);
            pc2.sendPackets((ServerBasePacket)new S_Dexup(pc2, 2, this._getBuffIconDuration));
          } else if (this._skillId == 109) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addStr(3);
            pc2.sendPackets((ServerBasePacket)new S_Strup(pc2, 2, this._getBuffIconDuration));
          } else if (this._skillId == 107) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            L1ItemInstance item = pc2.getInventory().getItem(this._itemobjid);
            if (item != null && item.getItem().getType2() == 1) {
              item.setSkillWeaponEnchant(pc2, this._skillId, 
                  this._skill.getBuffDuration() * 1000);
              pc2.sendPackets((ServerBasePacket)new S_PacketBox(154, this._skill.getCastGfx(), 
                    this._skill.getBuffDuration()));
            } else {
              pc2.sendPackets((ServerBasePacket)new S_ServerMessage(79));
            } 
          } else if (this._skillId == 12) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            L1ItemInstance item = pc2.getInventory().getItem(this._itemobjid);
            if (item != null && item.getItem().getType2() == 1) {
              pc2.sendPackets((ServerBasePacket)new S_ServerMessage(161, item.getLogName(), "$245", "$247"));
              item.setSkillWeaponEnchant(pc2, this._skillId, 
                  this._skill.getBuffDuration() * 1000);
            } else {
              pc2.sendPackets((ServerBasePacket)new S_ServerMessage(79));
            } 
          } else if (this._skillId == 8 || this._skillId == 48) {
            if (!(cha instanceof L1PcInstance))
              return; 
            L1PcInstance pc2 = (L1PcInstance)cha;
            if (pc2.getWeapon() == null) {
              pc2.sendPackets((ServerBasePacket)new S_ServerMessage(79));
              return;
            } 
            Iterator<L1ItemInstance> iterator2 = pc2.getInventory().getItems().iterator();
            while (iterator2.hasNext()) {
              L1ItemInstance item = iterator2.next();
              if (pc2.getWeapon().equals(item)) {
                pc2.sendPackets(
                    (ServerBasePacket)new S_ServerMessage(161, item.getLogName(), "$245", "$247"));
                item.setSkillWeaponEnchant(pc2, this._skillId, 
                    this._skill.getBuffDuration() * 1000);
                return;
              } 
            } 
          } else if (this._skillId == 21) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            L1ItemInstance item = pc2.getInventory().getItem(this._itemobjid);
            if (item != null && item.getItem().getType2() == 2 && 
              item.getItem().getType() == 2) {
              pc2.sendPackets((ServerBasePacket)new S_ServerMessage(161, item.getLogName(), "$245", "$247"));
              item.setSkillArmorEnchant(pc2, this._skillId, 
                  this._skill.getBuffDuration() * 1000);
            } else {
              pc2.sendPackets((ServerBasePacket)new S_ServerMessage(79));
            } 
          } else if (this._skillId == 159) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addAc(-7);
            pc2.sendPackets((ServerBasePacket)new S_SkillIconShield(7, this._getBuffIconDuration));
          } else if (this._skillId == 129) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addMr(10);
            pc2.sendPackets((ServerBasePacket)new S_SPMR(pc2));
          } else if (this._skillId == 137) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addWis(3);
            pc2.resetBaseMr();
          } else if (this._skillId == 138) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addWind(10);
            pc2.addWater(10);
            pc2.addFire(10);
            pc2.addEarth(10);
            pc2.sendPackets((ServerBasePacket)new S_OwnCharAttrDef(pc2));
          } else if (this._skillId == 147) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            int attr = pc2.getElfAttr();
            if (attr == 1) {
              pc2.addEarth(50);
            } else if (attr == 2) {
              pc2.addFire(50);
            } else if (attr == 4) {
              pc2.addWater(50);
            } else if (attr == 8) {
              pc2.addWind(50);
            } 
          } else if (this._skillId == 60 || this._skillId == 97) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.sendPackets((ServerBasePacket)new S_Invis(pc2.getId(), 1));
            pc2.broadcastPacketAll((ServerBasePacket)new S_RemoveObject((L1Object)pc2));
          } else if (this._skillId == 168) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addAc(-10);
            pc2.sendPackets((ServerBasePacket)new S_SkillIconShield(10, this._getBuffIconDuration));
          } else if (this._skillId == 151) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addAc(-6);
            pc2.sendPackets((ServerBasePacket)new S_SkillIconShield(6, this._getBuffIconDuration));
          } else if (this._skillId == 42) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addStr(5);
            pc2.sendPackets((ServerBasePacket)new S_Strup(pc2, 5, this._getBuffIconDuration));
          } else if (this._skillId == 26) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addDex(5);
            pc2.sendPackets((ServerBasePacket)new S_Dexup(pc2, 5, this._getBuffIconDuration));
          } else if (this._skillId == 148) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.sendPackets((ServerBasePacket)new S_PacketBoxIconAura(147, this._getBuffIconDuration));
          } else if (this._skillId == 155) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addDmgup(4);
            pc2.sendPackets((ServerBasePacket)new S_PacketBoxIconAura(154, this._getBuffIconDuration));
          } else if (this._skillId == 163) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.sendPackets((ServerBasePacket)new S_PacketBoxIconAura(162, this._getBuffIconDuration));
          } else if (this._skillId == 149) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addBowHitup(6);
            pc2.sendPackets((ServerBasePacket)new S_PacketBoxIconAura(148, this._getBuffIconDuration));
          } else if (this._skillId == 156) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addBowHitup(2);
            pc2.addBowDmgup(3);
            pc2.sendPackets((ServerBasePacket)new S_PacketBoxIconAura(155, this._getBuffIconDuration));
          } else if (this._skillId == 166) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addBowDmgup(6);
            pc2.addBowHitup(-1);
            pc2.sendPackets((ServerBasePacket)new S_PacketBoxIconAura(165, this._getBuffIconDuration));
          } else if (this._skillId == 55) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addAc(10);
            pc2.stopHpRegeneration();
          } else if (this._skillId == 54) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            if (pc2.getHasteItemEquipped() > 0)
              continue; 
            if (pc2.getMoveSpeed() != 2) {
              pc2.setDrink(false);
              pc2.setMoveSpeed(1);
              pc2.sendPackets((ServerBasePacket)new S_SkillHaste(pc2.getId(), 1, this._getBuffIconDuration));
              pc2.broadcastPacketAll((ServerBasePacket)new S_SkillHaste(pc2.getId(), 1, 0));
            } else {
              int skillNum2 = 0;
              if (pc2.hasSkillEffect(29)) {
                skillNum2 = 29;
              } else if (pc2.hasSkillEffect(76)) {
                skillNum2 = 76;
              } else if (pc2.hasSkillEffect(152)) {
                skillNum2 = 152;
              } 
              if (skillNum2 != 0) {
                pc2.removeSkillEffect(skillNum2);
                pc2.removeSkillEffect(54);
                pc2.setMoveSpeed(0);
                continue;
              } 
            } 
          } else if (this._skillId == 52 || this._skillId == 101 || this._skillId == 150) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.setBraveSpeed(4);
            pc2.sendPackets((ServerBasePacket)new S_SkillBrave(pc2.getId(), 4, this._getBuffIconDuration));
            pc2.broadcastPacketAll((ServerBasePacket)new S_SkillBrave(pc2.getId(), 4, 0));
          } else if (this._skillId == 204) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addDmgup(4);
            pc2.addHitup(4);
          } else if (this._skillId == 214) {
            L1PcInstance pc2 = (L1PcInstance)cha;
            pc2.addAc(-20);
          } 
        } 
        if (this._calcType == 2 || this._calcType == 4)
          if (this._skillId == 36 && ((L1MonsterInstance)cha).getNpcTemplate().isTamable()) {
            if (ConfigOther.petcountcha) {
              int petcost = 0;
              int petCount = 0;
              Object[] petlist = this._user.getPetList().values().toArray();
              if (petlist.length > ConfigOther.tamingmonstercount) {
                this._player.sendPackets((ServerBasePacket)new S_ServerMessage(489));
                return;
              } 
              Object[] array;
              int length2 = (array = petlist).length;
              int j = 0;
              while (j < length2) {
                Object pet = array[j];
                petcost += ((L1NpcInstance)pet).getPetcost();
                j++;
              } 
              int charisma = this._user.getCha();
              charisma -= petcost;
              charisma /= 2;
              if (charisma <= 0) {
                this._player.sendPackets((ServerBasePacket)new S_ServerMessage(489));
                return;
              } 
              L1SummonInstance summon = new L1SummonInstance(this._targetNpc, 
                  this._user, false);
              this._target = (L1Character)summon;
              summon.setPetcost(2);
            } else {
              int petcost = 0;
              Object[] petlist2 = this._user.getPetList().values().toArray();
              if (petlist2.length > ConfigOther.tamingmonstercount) {
                this._player.sendPackets((ServerBasePacket)new S_ServerMessage(489));
                return;
              } 
              Object[] array2;
              int j = (array2 = petlist2).length;
              int k = 0;
              while (k < j) {
                Object pet2 = array2[k];
                petcost += ((L1NpcInstance)pet2).getPetcost();
                k++;
              } 
              int charisma2 = this._user.getCha();
              if (this._player.isElf()) {
                charisma2 += 12;
              } else if (this._player.isWizard()) {
                charisma2 += 6;
              } 
              charisma2 -= petcost;
              if (charisma2 >= 6) {
                L1SummonInstance summon2 = new L1SummonInstance(this._targetNpc, 
                    this._user, false);
                this._target = (L1Character)summon2;
              } else {
                this._player.sendPackets((ServerBasePacket)new S_ServerMessage(319));
              } 
            } 
          } else if (this._skillId == 41) {
            int petcost = 0;
            Object[] petlist2 = this._user.getPetList().values().toArray();
            Object[] array2;
            int j = (array2 = petlist2).length;
            int k = 0;
            while (k < j) {
              Object pet2 = array2[k];
              petcost += ((L1NpcInstance)pet2).getPetcost();
              k++;
            } 
            int charisma2 = this._user.getCha();
            if (this._player.isElf()) {
              charisma2 += 12;
            } else if (this._player.isWizard()) {
              charisma2 += 6;
            } 
            charisma2 -= petcost;
            if (charisma2 >= 6) {
              L1SummonInstance summon2 = new L1SummonInstance(this._targetNpc, 
                  this._user, true);
              this._target = (L1Character)summon2;
            } else {
              this._player.sendPackets((ServerBasePacket)new S_ServerMessage(319));
            } 
          } else if (this._skillId == 23) {
            if (cha instanceof L1MonsterInstance) {
              L1Npc npcTemp = ((L1MonsterInstance)cha).getNpcTemplate();
              int weakAttr = npcTemp.get_weakAttr();
              if ((weakAttr & 0x1) == 1)
                cha.broadcastPacketAll((ServerBasePacket)new S_SkillSound(cha.getId(), 2169)); 
              if ((weakAttr & 0x2) == 2)
                cha.broadcastPacketAll((ServerBasePacket)new S_SkillSound(cha.getId(), 2167)); 
              if ((weakAttr & 0x4) == 4)
                cha.broadcastPacketAll((ServerBasePacket)new S_SkillSound(cha.getId(), 2166)); 
              if ((weakAttr & 0x8) == 8)
                cha.broadcastPacketAll((ServerBasePacket)new S_SkillSound(cha.getId(), 2168)); 
            } 
          } else if (this._skillId == 145) {
            if (cha instanceof L1SummonInstance) {
              L1SummonInstance summon3 = (L1SummonInstance)cha;
              summon3.broadcastPacketAll((ServerBasePacket)new S_SkillSound(summon3.getId(), 2245));
              summon3.returnToNature();
            } else if (this._user instanceof L1PcInstance) {
              this._player.sendPackets((ServerBasePacket)new S_ServerMessage(79));
            } 
          }  
        if (this._skill.getType() == 16 && this._calcType == 2 && undeadType == 1)
          this._dmg = this._heal; 
        if (this._skill.getType() == 16 && this._calcType == 2 && undeadType == 4)
          this._heal = 0; 
        if ((cha instanceof com.lineage.server.model.Instance.L1TowerInstance || cha instanceof com.lineage.server.model.Instance.L1DoorInstance) && this._heal < 0)
          this._heal = 0; 
        if (this._dmg != 0 || drainMana != 0)
          magic.commit(this._dmg, drainMana); 
        if (this._skill.getType() == 16 && this._heal != 0 && undeadType != 1) {
          if (this._skillId == 164 && ConfigElfSkill.IS_PET_BLESSING && 
            this._user instanceof L1PcInstance && this._player.getPetList() != null) {
            Iterator<L1NpcInstance> iterator3 = this._player.getPetList().values()
              .iterator();
            while (iterator3.hasNext()) {
              L1NpcInstance petNpc = iterator3.next();
              if (petNpc.isDead())
                continue; 
              if (petNpc.getMaster() == null)
                continue; 
              if (heal + petNpc.getCurrentHp() > petNpc.getMaxHp()) {
                petNpc.setCurrentHp(petNpc.getMaxHp());
                continue;
              } 
              petNpc.setCurrentHp(heal + petNpc.getCurrentHp());
            } 
          } 
          cha.setCurrentHp(this._heal + cha.getCurrentHp());
        } 
        if (heal > 0)
          this._user.setCurrentHp(heal + this._user.getCurrentHp()); 
        if (cha instanceof L1PcInstance) {
          L1PcInstance pc2 = (L1PcInstance)cha;
          pc2.turnOnOffLight();
          pc2.sendPackets((ServerBasePacket)new S_OwnCharAttrDef(pc2));
          pc2.sendPackets((ServerBasePacket)new S_OwnCharStatus(pc2));
          sendHappenMessage(pc2);
        } 
        addMagicList(cha, false);
      } 
      if (this._skillId == 13 || this._skillId == 72 || this._skillId == 194 || this._skillId == 213)
        detection(this._player); 
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  private void detection(L1PcInstance pc) {
    if (!pc.isGmInvis() && pc.isInvisble()) {
      pc.delInvis();
      pc.beginInvisTimer();
    } 
    Iterator<L1PcInstance> iterator = World.get().getVisiblePlayer((L1Object)pc).iterator();
    while (iterator.hasNext()) {
      L1PcInstance tgt = iterator.next();
      if (!tgt.isGmInvis() && tgt.isInvisble())
        tgt.delInvis(); 
    } 
    WorldTrap.get().onDetection(pc);
  }
  
  private boolean isTargetCalc(L1Character cha) {
    L1PetInstance pet;
    if (this._skill.getTarget().equals("attack") && this._skillId != 18 && isPcSummonPet(cha) && (
      this._player.isSafetyZone() || cha.isSafetyZone() || this._player.checkNonPvP(this._player, cha)))
      return false; 
    switch (this._skillId) {
      case 66:
        if (this._user.getId() == cha.getId())
          return false; 
        break;
      case 76:
        if (this._user.getId() == cha.getId())
          return false; 
        if (cha instanceof L1SummonInstance) {
          L1SummonInstance summon = (L1SummonInstance)cha;
          if (this._user.getId() == summon.getMaster().getId())
            return false; 
          break;
        } 
        if (!(cha instanceof L1PetInstance))
          break; 
        pet = (L1PetInstance)cha;
        if (this._user.getId() == pet.getMaster().getId())
          return false; 
        break;
      case 69:
        if (this._user.getId() != cha.getId())
          return false; 
        break;
    } 
    return true;
  }
  
  private boolean isPcSummonPet(L1Character cha) {
    switch (this._calcType) {
      case 1:
        return true;
      case 2:
        if (cha instanceof L1SummonInstance) {
          L1SummonInstance summon = (L1SummonInstance)cha;
          if (summon.isExsistMaster())
            return true; 
        } 
        return !(!(cha instanceof L1PetInstance) && !(cha instanceof com.lineage.server.model.Instance.L1DeInstance));
    } 
    return false;
  }
  
  private boolean isTargetFailure(L1Character cha) {
    boolean isTU = false;
    boolean isErase = false;
    boolean isManaDrain = false;
    int undeadType = 0;
    if (cha instanceof com.lineage.server.model.Instance.L1TowerInstance || cha instanceof com.lineage.server.model.Instance.L1DoorInstance)
      return true; 
    if (!(cha instanceof L1PcInstance)) {
      if (cha instanceof L1MonsterInstance)
        isTU = ((L1MonsterInstance)cha).getNpcTemplate().get_IsTU(); 
      if (cha instanceof L1MonsterInstance)
        isErase = ((L1MonsterInstance)cha).getNpcTemplate().get_IsErase(); 
      if (cha instanceof L1MonsterInstance)
        undeadType = ((L1MonsterInstance)cha).getNpcTemplate().get_undead(); 
      if (cha instanceof L1MonsterInstance)
        isManaDrain = true; 
      return !((this._skillId != 18 || (undeadType != 0 && undeadType != 2)) && (this._skillId != 18 || isTU) && ((
        this._skillId != 153 && this._skillId != 29 && this._skillId != 39 && this._skillId != 76 && 
        this._skillId != 152 && this._skillId != 167) || isErase) && (
        this._skillId != 39 || isManaDrain));
    } 
    if (this._calcType == 1 && this._player.checkNonPvP(this._player, cha)) {
      L1PcInstance pc = (L1PcInstance)cha;
      return (this._player.getId() != pc.getId() && (
        pc.getClanid() == 0 || this._player.getClanid() != pc.getClanid()));
    } 
    return false;
  }
  
  private boolean isUseCounterMagic(L1Character cha) {
    if (this._isCounterMagic && cha.hasSkillEffect(31)) {
      cha.removeSkillEffect(31);
      int castgfx2 = SkillsTable.get().getTemplate(31).getCastGfx2();
      cha.broadcastPacketAll((ServerBasePacket)new S_SkillSound(cha.getId(), castgfx2));
      if (cha instanceof L1PcInstance) {
        L1PcInstance pc = (L1PcInstance)cha;
        pc.sendPackets((ServerBasePacket)new S_SkillSound(pc.getId(), castgfx2));
      } 
      return true;
    } 
    return false;
  }
  
  private void SpawnPoisonArea(L1Location baseloc) {
    int locX = 0;
    int locY = 0;
    int i = 0;
    while (i < 3) {
      int j = 0;
      while (j < 3) {
        switch (this._user.getHeading()) {
          case 0:
            locX = -1 + j;
            locY = -1 * (-3 + i);
            break;
          case 1:
            locX = -1 * (2 + j - i);
            locY = -1 * (-4 + j + i);
            break;
          case 2:
            locX = -1 * (3 - i);
            locY = -1 + j;
            break;
          case 3:
            locX = -1 * (4 - j - i);
            locY = -1 * (2 + j - i);
            break;
          case 4:
            locX = 1 - j;
            locY = -1 * (3 - i);
            break;
          case 5:
            locX = -1 * (-2 - j + i);
            locY = -1 * (4 - j - i);
            break;
          case 6:
            locX = -1 * (-3 + i);
            locY = 1 - j;
            break;
          case 7:
            locX = -1 * (-4 + j + i);
            locY = -1 * (-2 - j + i);
            break;
        } 
        L1EffectInstance effect = L1SpawnUtil.spawnEffect(86125, 3, baseloc.getX() - locX, 
            baseloc.getY() - locY, this._user.getMapId(), this._user, 20011);
        effect.broadcastPacketAll((ServerBasePacket)new S_SkillSound(effect.getId(), 1263));
        j++;
      } 
      i++;
    } 
  }
}
